package com.nut.lmsc.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nut.lmsc.common.Result;
import com.nut.lmsc.entity.Brand;
import com.nut.lmsc.mapper.BrandMapper;
import com.nut.lmsc.service.BrandService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Set;

@Service
@Slf4j
public class BrandServiceImpl implements BrandService {

    @Autowired
    private BrandMapper brandMapper;

    @Override
    public Result<IPage<Brand>> listPage(String name, Integer pageNo, Integer pageSize) {
        Page<Brand> page = new Page<>(pageNo, pageSize);
        IPage<Brand> list = brandMapper.listPage(page, name);
        return Result.ok(list);
    }

    @Override
    public Result<Brand> getById(Serializable id) {
        Brand brand = brandMapper.selectById(id);
        return Result.ok(brand);
    }

    @Override
    public Result add(Brand brand) {
        brandMapper.insert(brand);
        return Result.ok();
    }

    @Override
    public Result updateById(Brand brand) {
        brandMapper.updateById(brand);
        return Result.ok();
    }

    @Override
    public Result deleteByIds(Set<Integer> ids) {
        for (Integer id : ids) {
            brandMapper.deleteById(id);
        }
        return Result.ok();
    }
}